<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui" xmlns:f="http://java.sun.com/jsf/core"
                xmlns:constants="http://www.tuanzi.com/constants/tags"
                xmlns:security="http://www.springframework.org/security/tags"
                template="/templates/template.xhtml">
    <ui:define name="title">推荐位管理</ui:define>
    <ui:define name="content">
        <h:form>
            <p:dialog header="操作执行中,请稍候" widgetVar="doing" modal="true" closable="false" resizable="false" draggable="false"/>
            <p:defaultCommand target="search"/>
            <div class="topbar clearfix" style="background: -webkit-linear-gradient(top,#f6f7f9 0,#ebedf0 100%);">
                <p:toolbar>
                    <f:facet name="left">
                        <p:commandButton id="toggler" type="button" value="展示选择"
                                         style="width: auto;"
                                         icon="ui-icon-calculator"/>
                        <p:commandButton id="flush" value="刷新缓存" icon="fa fa-bolt"
                                         actionListener="#{healthHeadlineRecommendListBean.onFlushCache()}"
                                         update="@form"/>
                        <p:columnToggler datasource="recordDataTable" trigger="toggler"/>
                    </f:facet>
                    <f:facet name="right">
                        <p:commandButton id="search" value="查询" icon="fa fa-search"
                                         onstart="PF('doing').show()"
                                         rendered="#{healthHeadlineRecommendListBean.isNormal()}"
                                         update="@form"/>
                        <p:commandButton value="重置" icon="fa fa-refresh"
                                         rendered="#{healthHeadlineRecommendListBean.isNormal()}"
                                         actionListener="#{healthHeadlineRecommendListBean.onReset}"
                                         process="@this" update="@form"/>
                        <p:commandButton icon="fa fa-plus" value="新增"
                                         action="#{healthHeadlineRecommendListBean.onAdd}"
                                         rendered="#{healthHeadlineRecommendListBean.isNormal() and security:areAllGranted('LOAN_FAMILY_TAGS_FIRST_PARTY_ADD')}">
                            <f:setPropertyActionListener value="/views/miniApps/recommend/health-headline-recommend-list.xhtml"
                                                         target="#{currentUserBean.back}"/>
                        </p:commandButton>
                    </f:facet>
                </p:toolbar>
            </div>
            <div class="ui-fluid" style="padding-top: 30px;">
                <div class="ui-g">
                    <div class="ui-g-12">
                        <div class="card">
                            <h1>查询条件</h1>
                            <p:panelGrid columns="8" layout="grid"
                                         columnClasses="ui-grid-col-1,ui-grid-col-2"
                                         styleClass="ui-panelgrid-blank"
                                         style="border:0px none; background-color:transparent;text-align:center;">
                                <p:outputLabel for="selectRecommendDateStart" value="推荐上线时间开始"/>
                                <p:calendar id="selectRecommendDateStart" value="#{healthHeadlineRecommendListBean.$.startRecommendDate}"
                                            locale="#{constants:get('LOCALE')}"
                                            timeZone="#{constants:get('TIME_ZONE')}"
                                            pattern="#{constants:get('DATE_FORMAT')}"/>
                                            
                                <p:outputLabel for="selectRecommendDateEnd" value="推荐上线时间结束"/>
                                <p:calendar id="selectRecommendDateEnd" value="#{healthHeadlineRecommendListBean.$.endtRecommendDate}"
                                            locale="#{constants:get('LOCALE')}"
                                            timeZone="#{constants:get('TIME_ZONE')}"
                                            pattern="#{constants:get('DATE_FORMAT')}"/>
                                            
                                <p:outputLabel for="inputTitle" value="文章标题"/>
                                <p:inputText id="inputTitle" value="#{healthHeadlineRecommendListBean.$.title}"/>
                                
                                <p:outputLabel for="selectMiniAppsCode" value="小程序"/>
                                <p:selectCheckboxMenu id="selectMiniAppsCode" value="#{healthHeadlineRecommendListBean.$.miniAppsCodeList}"
                                                      updateLabel="true" multiple="true" filter="true">
                                    <f:selectItems value="#{healthHeadlineRecommendListBean.miniAppsList}" var="miniApps"
                                    	itemValue="#{miniApps.relationCode}" itemLabel="#{miniApps.relationName}"/>
                                </p:selectCheckboxMenu>
                                
                                <p:outputLabel for="selectAdvertise" value="广告位"/>
                                <p:selectCheckboxMenu id="selectAdvertise" value="#{healthHeadlineRecommendListBean.$.advertiseList}"
                                                      updateLabel="true" multiple="true" filter="true" filterMatchMode="contains">
                                    <f:selectItems value="#{healthHeadlineRecommendListBean.advertiseList}" var="ad"
                                    	itemValue="#{ad.relationCode}" itemLabel="#{ad.relationName}"/>
                                </p:selectCheckboxMenu>

                                <p:outputLabel for="selectRecommendStatus" value="广告位状态"/>
                                <p:selectOneMenu id="selectRecommendStatus" value="#{healthHeadlineRecommendListBean.$.recommendStatus}">
                                	<f:selectItem itemLabel="请选择" itemValue="" noSelectionOption="true"/>
                                    <f:selectItem itemLabel="下线" itemValue="0" noSelectionOption="true"/>
                                   	<f:selectItem itemLabel="上线" itemValue="1" noSelectionOption="true"/>
                                </p:selectOneMenu>
                                
                            </p:panelGrid>
                        </div>
                        <div class="card">
                            <p:dataTable id="recordDataTable"
                                         style="width: 100%;text-align:center"
                                         var="record"
                                         value="#{healthHeadlineRecommendListBean.lazyDataModel}"
                                         rows="20"
                                         lazy="true"
                                         paginator="true"
                                         paginatorTemplate="#{constants:get('PAGINATOR_TEMPLATE')}"
                                         rowsPerPageTemplate="#{constants:get('ROWS_PER_PAGE_TEMPLATE')}"
                                         emptyMessage="#{constants:get('EMPTY_MESSAGE')}"
                                         scrollable="true"
                                         reflow="true"
                                         selection="#{healthHeadlineRecommendListBean.selectedRecords}"
                                         resizableColumns="true">
                                <p:column headerText="操作" rendered="#{healthHeadlineRecommendListBean.isNotBatch()}">
                                    <p:splitButton icon="fa fa-eye"
                                                   action="#{healthHeadlineRecommendListBean.onEdit(record.articleRelationId)}"
                                                   process="@this">
                                        <f:setPropertyActionListener
                                                value="/views/miniApps/recommend/health-headline-recommend-list.xhtml"
                                                target="#{currentUserBean.back}"/>
                                                
                                        <p:menuitem value="广告位上线" icon="fa fa-arrow-up"
                                                    action="#{healthHeadlineRecommendListBean.onAdvertiseOnline(record.articleRelationId)}"
                                                    process="@this" update="@form"
                                                    rendered="#{record.advertiseStatus == 0 and security:areAllGranted('LOAN_FAMILY_TAGS_FIRST_PARTY_ONLINE')}"/>
                                        <p:menuitem value="广告位下线" icon="fa fa-arrow-down"
                                                    actionListener="#{healthHeadlineRecommendListBean.onAdvertiseOffline(record.articleRelationId)}"
                                                    process="@this" update="@form"
                                                    rendered="#{record.advertiseStatus == 1 and security:areAllGranted('LOAN_FAMILY_TAGS_FIRST_PARTY_OFFLINE')}"/>
                                    	<p:menuitem value="删除" icon="fa fa-remove"
                                         	actionListener="#{healthHeadlineRecommendListBean.onDeleteAdvertise(record.articleRelationId)}"
                                         	update="@form">
				                            <p:confirm header="提示信息" message="是否确定删除广告位?"
				                                       icon="ui-icon-alert"/>
				                        </p:menuitem>
                                    
                                    </p:splitButton>
                                </p:column>
                                <p:column headerText="小程序">
                                    <h:outputText value="#{record.miniAppsListText}"/>
                                </p:column>
                                <p:column headerText="推荐位" style="text-align:center;">
                                    <h:outputText value="#{record.advertiseName}"/>
                                </p:column>
                                <p:column headerText="权重值" style="text-align:center;">
                                    <h:outputText value="#{record.weight}"/>
                                </p:column>
                                <p:column headerText="文章名" style="text-align:center;">
                                    <h:outputText value="#{record.articleTitle}"/>
                                </p:column>
                                <p:column headerText="广告位上线时间" style="text-align:center;">
                                    <h:outputText value="#{record.advertiseOnlineDate}"/>
                                </p:column>
                                <p:column headerText="操作人" style="text-align:center;">
                                	<h:outputText value="#{record.updator}"/>
                                </p:column>
                                <p:column headerText="推荐状态" style="text-align:center;">
                                    <h:outputText
                                            value="#{healthHeadlineRecommendListBean.translate(DictionaryCode.ONLINE_OFFLINE_STATUS,record.advertiseStatus)}"/>
                                </p:column>
                            </p:dataTable>
                        </div>
                    </div>
                </div>
            </div>
        </h:form>
    </ui:define>
</ui:composition>
